“h5_crtdat18”

Information

The example shown in this file appears at: http://www.hdfgroup.org/HDF5/Tutor/crtdat.html (accessed 10 July 2011)

The example shown in this file is following the tutorial: http://www.hdfgroup.org/HDF5/Tutor/introductory.html

Good references for the shown HDF5 functions include:
http://www.hdfgroup.org/HDF5/doc/RM/RM_H5Front.html
http://www.hdfgroup.org/HDF5/doc/RM/

Prepared 10 July 2011 by Scot Martin for Windows 7, 64-bit, Mathematica version 8.0.1.

“c” code we seek to replicate in this example

/*
 *   Creating and closing a dataset.
 */

#include "hdf5.h"
#define FILE "dset.h5"

int main() {

   hid_t       file_id, dataset_id, dataspace_id;  /* identifiers */
   hsize_t     dims[2];
   herr_t      status;

   /* Create a new file using default properties. */
   file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

   /* Create the data space for the dataset. */
   dims[0] = 4; 
   dims[1] = 6; 
   dataspace_id = H5Screate_simple(2, dims, NULL);

   /* Create the dataset. */
   dataset_id = H5Dcreate(file_id, "/dset", H5T_STD_I32BE, dataspace_id, 
                          H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

   /* End access to the dataset and release resources used by it. */
   status = H5Dclose(dataset_id);

   /* Terminate access to the data space. */ 
   status = H5Sclose(dataspace_id);

   /* Close the file. */
   status = H5Fclose(file_id);
}

Implementation in Mathematica

SetDirectory[NotebookDirectory[]]

Needs["HDF5`"]

file=FileNameJoin[{Directory[],"dset.h5"}]

fileID=H5Fcreate[file,H5FuACCuTRUNC,H5PuDEFAULT,H5PuDEFAULT]

dataSpaceID=H5ScreateUsimple[2,{4,6},Null]

Below, the command “H5Tcopy[H5TuNATIVEuINT]” could be expected. Yet it does not quite work on the fundamental types, i.e., it returns as -1 indicating an error code. I took my best look at source code but cannot quite figure out a solution. 

The equivalent command is “H5T`copy[H5TuNATIVEuINT]@Id[]” in .NET formulation. Therefore, mix and match with the DotNet. It is not pretty but it works. 

The problem with using the DotNet code exclusively is that I could not coax functions such as H5D`read and H5D`write to work. It seems to have to do with the ‘generics’ format.

H5Tcopy does work fine on objects that already have identifies, like datasets, etc.

Bottom line: “H5T`copy[H5TuNATIVEuINT]@Id[]” is used in place of “H5Tcopy[H5TuNATIVEuINT]”.

dataSetID=H5Dcreate[fileID,"/dset",H5T`copy[H5TuNATIVEuINT]@Id[],dataSpaceID,H5PuDEFAULT,H5PuDEFAULT,H5PuDEFAULT]

H5Dclose[dataSetID]

H5Sclose[dataSpaceID]

H5Fclose[fileID]